import Taro , { Component, setNavigationBarTitle } from '@tarojs/taro';
import { View, Text , Button} from '@tarojs/components';
import './index.scss';
import { articleDetail } from '../../../services/article';
import NavigationBar from '../../../components/navigationBar/index';

export default class Index extends Component {

  config = {
      navigationBarTitleText: ''
  }

  state = {
    content: null,
    navigationBarHeight: Taro.getStorageSync('navigationBarHeight'),
    showBtn: false,
  }

  componentWillMount () {
    const {id, showBtn = 0} = this.$router.params;
    articleDetail({
      id
    }).then(res => {
      res.content = res.content.replace(/\<img/gi, '<img style="width: 100% !important; class="rich-img"');
      this.setState({
        content: res.content,
        showBtn: Boolean(showBtn),
      })
    })
  }
  componentDidMount () {}
  componentWillReceiveProps (nextProps,nextContext) {}
  componentWillUnmount () {}
  componentDidShow () {}
  componentDidHide () {}
  componentDidCatchError () {}
  componentDidNotFound () {}

  callPhone() {
    Taro.makePhoneCall({
      phoneNumber: Taro.getStorageSync('setting').mobile
    })
  }

  render() {
    const { content, showBtn } = this.state;
    return (
      <View className="customized" style={`margin-top: ${navigationBarHeight}`}>
        <NavigationBar text={showBtn ? '定制' : ''} />
        <View className="content">
          <RichText className="rich-text" nodes={content}></RichText>
        </View>
      </View>
    );
  }
}
